package com.hdhere.domain.common.util;

import java.util.concurrent.atomic.AtomicInteger;

/*******************************************************************************************
 * 类描述：  
 *
 * @author: dustin
 * @date: 2019-03-24 19:00
 * @Description:
 * @version 1.0
 *
 *
 * Version    Date       ModifiedBy                 Content  
 * -------- ---------    ----------         ------------------------  
 * 1.0      2019/3/24       dustin                               
 *******************************************************************************************
 */
public class IdWorker {

    private static AtomicInteger counter = new AtomicInteger(0);

    /**
     * gen id
     */
    public static long nextId() {
        if (counter.get() > 999999) {
            counter.set(1);
        }
        long time = System.currentTimeMillis();
        long returnValue = time * 100 + counter.incrementAndGet();
        return returnValue;
    }

    private static long incrementAndGet() {
        return counter.incrementAndGet();
    }

    public static void main(String[] args) {

        Long begin = System.currentTimeMillis();
        String s = "123";
        for(int i=0;i<1000000;i++){
            s.trim();
        }
        System.out.println("用时："+ (System.currentTimeMillis() - begin));

        System.out.println(IdWorker.nextId());
        System.out.println(IdWorker.nextId());
        System.out.println(IdWorker.nextId());
        System.out.println(IdWorker.nextId());
    }


}
